// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  try {
    const db = cloud.database()
    const _ = db.command
    //这里的update依据是event._id
    console.log(event.name);
    return await db.collection("product").where({
      name: db.RegExp({
        regexp: event.name,
        options: 'i',
      })
    })
    .update({
      data:{
        _count:_.inc(1)
      }
    })
  } catch (e) {
    console.error(e)
  }
}